#include "usart.h"
#include "modbus.h"
#include "device_usart.h"

//中段服务函数进入
void HAL_UART_RxCpltCallback(UART_HandleTypeDef huart)
{
    if(huart == USART0)
    {
        if(!REN0)
        {
            usart_data_receive(USART0);
            return;
        }
        uart0_rx_pending = 1;
        if(Uart0_FrameEnded())
            uart0_len = 0;
        timer_counter_value_config(TIMER5, 65536-1000);
        timer_flag_clear(TIMER5, TIMER_FLAG_UP);
        uart0_buf[UART0_BUF_MASK & uart0_len++] = (uchar)usart_data_receive(USART0);
        uart0_timestamp = timer_counter_read(TIMER5);
    }
}

void HAL_UART_TxCpltCallback(UART_HandleTypeDef huart)
{
    if(huart == USART0)
    {
        uart0_tx_pending = 1;
        if(uart0_len)
        {
            usart_data_transmit(USART0, *uart0_tx_ptr++);
            --uart0_len;
        }
        else{
            uart0_tx_pending = 0;
            usart_interrupt_disable(USART0, USART_INT_TBE);
        }
    }
}


